#include "../include/client.h"

int  client::clientinit()
{
#ifdef _WIN32
    WSADATA wsa;
    if(WSAStartup(0x0202,&wsa) == -1)
    {
        return -1;
    }
    else
    {
        return 1;
    }

#endif
#ifdef linux
    return 1;
#endif
}
//lay para can thiet
int client::clientcreatesocket()
{
    cl = socket(AF_INET,SOCK_STREAM,IPPROTO_IP);
    if(cl <= 0 )
    {
        return -1;

    }
    else
    {
        return 1;
    }

}
int client::clientconnect()
{
    int con = connect(cl,(sockaddr *)&server,sizeof(server));
    if(con == -1)
    {
        return -1;

    }
    else
    {
        return 1;
    }

}
int client::clientsend()
{

    int size = send(cl,(char *)&sen,sizeof(sen),0);
    return size;

}

int client::clientrecv()
{
    int size =  recv(cl,(char*)&rec,sizeof(rec),0);
    return size;
}
void client::clientgetparameters()
{
    cout<<endl<<"Server ip : ";
    cin>>this->serverip;
    cout<<endl;
    this->port = 9999;
    server.sin_family = AF_INET;
    server.sin_addr.s_addr = inet_addr(serverip);
    server.sin_port = htons(port);

}
void client::clientcleanup()
{
#ifdef _WIN32
    WSACleanup();
#endif
}
void client::clientclose()
{
#ifdef _WIN32
    closesocket(cl);
    clientcleanup();
#endif
#ifdef linux
    close(cl);
#endif
}
client::client()
{
    memset(this->serverip,0,sizeof(serverip));
    this->port = -1;
    this->cl = -1;
}
client::~client()
{
    memset(this->serverip,0,sizeof(serverip));
    this->port = -1;
    this->cl = -1;
}
